package guess;

/**
 * 裁判类
 */
public class Jug {
    private Player player;
    private Computer computer;

    public Jug() {
    }

    public Jug(Player player, Computer computer) {
        this.player = player;
        this.computer = computer;
    }
    public String showGuessInfo(int result){
        if(result == 0){
            return "剪刀";
        }else if(result == 1){
            return "石头";
        }else{
            return "布";
        }
    }
    /**
     * 裁判检查猜拳的结果来判定谁赢或谁输
     */
    public void check(){
        for(int i = 0;i < 5;i++){
            System.out.println("猜拳开始，现在是第"+(i+1)+"轮");
            int playerResult = this.player.guess();
            int computerResult = this.computer.guess();
            System.out.println("玩家出拳："+showGuessInfo(playerResult));
            System.out.println("电脑出拳："+showGuessInfo(computerResult));

            if(playerResult > computerResult){
                if(playerResult - computerResult == 2){
                    this.player.controlScore(-1);
                    this.computer.controlScore(1);
                    System.out.println("电脑赢");
                }else{
                    this.player.controlScore(1);
                    this.computer.controlScore(-1);
                    System.out.println("玩家赢");
                }
            }else if(playerResult < computerResult){
                if(computerResult -  playerResult== 2){
                    this.player.controlScore(1);
                    this.computer.controlScore(-1);
                    System.out.println("玩家赢");
                }else{
                    this.player.controlScore(-1);
                    this.computer.controlScore(1);
                    System.out.println("电脑赢");
                }
            }else{
                System.out.println("平局");
            }
        }
        if(this.player.getScore() > this.computer.getScore()){
            System.out.println("玩家"+this.player.getName()+"获得最后的胜利，分数为："+this.player.getScore());
        }else if(this.player.getScore() < this.computer.getScore()){
            System.out.println("电脑"+this.computer.getName()+"获得最后的胜利，分数为："+this.computer.getScore());
        }else{
            System.out.println("双方平局");
        }

    }

    public Player getPlayer() {
        return player;
    }

    public void setPlayer(Player player) {
        this.player = player;
    }

    public Computer getComputer() {
        return computer;
    }

    public void setComputer(Computer computer) {
        this.computer = computer;
    }
}
